﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Simhopp.Common
{
    /// <summary>
    /// The DivingType class provides a description of a dive type.
    /// </summary>
    [Serializable]
    public class DivingType : System.Object, ISerializable
    {
        #region CONTRUCTOR REGION
        /// <summary>
        /// Default constructor
        /// </summary>
        public DivingType()
        {
            ID = "";
            TypeName = "";
            Height = Heights.OneMeter;
            DifficultyFactor = 0.0;
        }
        #endregion
        #region PROPERTY REGION

        /// <summary>
        /// Unique key ID for representing a specific jumptype and height.
        /// </summary>
        public int KeyId { get; set; }

        /// <summary>
        /// Property ID gets or sets the type ID of the dive.
        /// </summary>
        public string ID { get; set; }

        /// <summary>
        /// Property TypeName gets or sets the type name of the dive.
        /// </summary>
        public string TypeName { get; set; }

        /// <summary>
        /// Property Height gets or sets the height of the dive.
        /// </summary>
        public Heights Height { get; set; }

        /// <summary>
        /// Property DifficultyFactor gets or sets the difficulty factor of the dive.
        /// </summary>
        public double DifficultyFactor { get; set; }

        #endregion
        #region METHOD REGION

        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return false;
            }

            // If parameter cannot be cast to DivingType return false.
            DivingType p = obj as DivingType;
            if ((System.Object)p == null)
            {
                return false;
            }

            // Return true if the fields match:
            if (this.ID.CompareTo(p.ID) == 0)
            {
                return true;
            }
            return false;
        }

        #endregion
        #region SERIALIZE/DESERIALIZE
        /// <summary>
        /// Adds the class specific information used in the serialization of an object.
        /// </summary>
        /// <param name="info">The class specific information.</param>
        /// <param name="context">Describes the source and destination of a given serialized stream.</param>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("KeyId", KeyId, typeof(int));
            info.AddValue("ID", ID, typeof(string));
            info.AddValue("TypeName", TypeName, typeof(string));
            info.AddValue("Height", Height, typeof(Heights));
            info.AddValue("DifficultyFactor", DifficultyFactor, typeof(double));
        }
        /// <summary>
        /// Constructor used in the deserialization of an object.
        /// </summary>
        /// <param name="info">The class specific information.</param>
        /// <param name="context">Describes the source and destination of a given serialized stream.</param>
        protected DivingType(SerializationInfo info, StreamingContext context)
        {
            KeyId = (int) info.GetValue("KeyId", typeof(int));
            ID = (string) info.GetValue("ID", typeof(string));
            TypeName = (string) info.GetValue("TypeName", typeof(string));
            Height = (Heights) info.GetValue("Height", typeof(Heights));
            DifficultyFactor = (double) info.GetValue("DifficultyFactor", typeof(double));
        }
        #endregion
    }
}

